<!DOCTYPE html>
<html lang="en">
	<head>
		<title> New Document </title>
		<meta charset="utf-8">
		<meta name="Author" content="">
		<meta name="Keywords" content="">
		<meta name="Description" content="">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<!-- Bootstrap -->
		<link href="../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen">
		<link href="../../resources/css/style.css" rel="stylesheet">
	</head>
<body class="main">
	<div class="wrap">
		<form class="form-horizontal" id="addUser" method="post" action="${webRoot}user/web/addUser.do">
		  <div class="control-group">
		   <ul class="breadcrumb">
		    <li><span id="test">您当前的位置：</span><a href="#">首页</a> <span class="divider">>></span></li>
		    <li><a href="#">用户列表</a> <span class="divider">>></span></li>
		    <li class="active">${adduser}</li>
	     </ul>
		    <label class="control-label" for="user_Name">用户名</label>
		    <div class="controls">
		      <input type="text" id="user_Name" name="user_Name">
		    </div>
		  </div>
		  <div class="control-group">
		    <label class="control-label" for="user_Pass">密码</label>
		    <div class="controls">
		      <input type="password" id="user_Pass" name="user_Pass">
		    </div>
		  </div>
		  <div class="control-group">
		    <label class="control-label" for="user_Phone">联系电话</label>
		    <div class="controls">
		      <input type="tel" id="user_Phone" name="user_Phone">
		    </div>
		  </div>
		  <div class="control-group">
		    <label class="control-label" for="user_Role">类别</label>
		    <div class="controls">
				<select id="user_Role" name="user_Role">
				  <option value="shop">商户</option>
				  <option value="admin">管理员</option>
				</select>
		    </div>
		  </div>		  		  
		  <div class="control-group">
		    <div class="controls">
		      <button type="button" class="btn" id="insertTo" onclick="sendValue();">确定添加</button>
		    </div>
		  </div>
		</form>		
	</div>			
	<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
	<script src="../../resources/js/bootstrap.min.js"></script>
	<script src="../../resources/js/js.js"></script>
	<script type="text/javascript">
		function sendValue(){
			var reg =/^1[3|4|5|8][0-9]\d{4,8}$/; 
			var username =$("#user_Name").val();
			var password =$("#user_Pass").val();
			var telephone = $("#user_Phone").val();
			var role = $("#role").val();
			if($.trim(username) == null ||$.trim(username) =="" ){
				alert("用户名不能为空！");
				return ;
			}else if($.trim(username) != null&&$.trim(username) !=""){
				var goodsName = escape(escape(username));
				$.ajax({url:"${webRoot}/user/web/checkUserName.do?username="+goodsName,
					   type:"post",
					   cache:"false",
					   error : function() {
						   alert("系统繁忙，请稍后再试！");
						},
					   success:function(msg){
						  if($.trim(msg) == "1"){
							  alert("用户名已存在！");
							  return ;
						  }else{
							  if($.trim(password) == null ||$.trim(password) ==""){
									alert("密码不能为空！");
									return ;
								}
								if($.trim(telephone) == null ||$.trim(telephone) ==""){
									alert("联系方式不能为空！");
									return ;
								}
								if(!(reg.test(telephone))){
									alert("手机号码输入格式不正确！");
									return ;
								}
								document.getElementById("addUser").submit();
						  }
					   }
					});
			}
		}
		</script>
</body>
</html>
